package com.sundi.ecmarket.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sundi.ecmarket.config.ExcelBean;
import com.sundi.ecmarket.config.ExcelUtils;
import com.sundi.ecmarket.dto.AfterDto;
import com.sundi.ecmarket.dto.BrandDto;
import com.sundi.ecmarket.entity.EcAftersale;
import com.sundi.ecmarket.entity.EcBrand;
import com.sundi.ecmarket.mapper.EcAftersaleMapper;
import com.sundi.ecmarket.service.IEcAftersaleService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 售后表 服务实现类
 * </p>
 *
 * @author Mht
 * @since 2020-02-23
 */
@Service
public class EcAftersaleServiceImpl extends ServiceImpl<EcAftersaleMapper, EcAftersale> implements IEcAftersaleService {

    @Override
    public List<EcAftersale> selectAfterList(AfterDto afterDto) {
        return this.baseMapper.selectAfterList(afterDto);
    }

    @Override
    public void updateLogicDel(Integer id) {
        this.baseMapper.updateLogicDel(id);
    }


    @Override
    public XSSFWorkbook downLoadGoodsExcel(AfterDto afterDto) throws Exception {
        PageHelper.startPage(afterDto.getPageNo(),afterDto.getPageSize());
        Wrapper wrapper = new EntityWrapper();

        if (StringUtils.isNotBlank(afterDto.getAftersaleSn())){
            wrapper.like("aftersaleSn",afterDto.getAftersaleSn());
        }
        List<EcAftersale> list = this.selectList(wrapper);
        PageInfo<EcAftersale> pageInfo = new PageInfo(list);
        Map<Integer,List<ExcelBean>> map = new HashMap<Integer,List<ExcelBean>>();
        List<ExcelBean> excelBeans = new ArrayList<>();
        excelBeans.add(new ExcelBean("id","id",0));
        excelBeans.add(new ExcelBean("售后编号","aftersaleSn",0));
        excelBeans.add(new ExcelBean("订单ID","orderId",0));
        excelBeans.add(new ExcelBean("用户ID","userId",0));
        excelBeans.add(new ExcelBean("售后类型","type",0));
        excelBeans.add(new ExcelBean("退款原因","reason",0));
        excelBeans.add(new ExcelBean("退款金额","amount",0));
        excelBeans.add(new ExcelBean("退款金额","amount",0));
        excelBeans.add(new ExcelBean("退款凭证图片链接数组","pictures",0));
        excelBeans.add(new ExcelBean("退款说明","comment",0));
        excelBeans.add(new ExcelBean("售后状态","status",0));
        excelBeans.add(new ExcelBean("管理员操作时间","handleTime",0));

        map.put(0,excelBeans);

        return ExcelUtils.createExcelFile(EcAftersale.class,pageInfo.getList(),map,"商铺列表");
    }
}
